# Created by 黄景涛
# DATE: 2025/3/6
import os
import yaml
from pathlib import Path


# 项目根目录
ROOT_PATH = Path(__file__).parent.parent.as_posix()

# config配置
with open(os.path.join(ROOT_PATH, 'config', 'config.yaml'), mode='r', encoding='utf8') as f:
    cfg = yaml.safe_load(f)


# 日志颜色配置
class LogColors:
    RESET = "\033[0m"
    BLACK = "\033[30m"
    RED = "\033[31m"
    GREEN = "\033[32m"
    YELLOW = "\033[33m"
    BLUE = "\033[34m"
    MAGENTA = "\033[35m"
    CYAN = "\033[36m"
    WHITE = "\033[37m"


# 配置日志系统， 固定格式
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s 【%(levelname)-8s】 【%(pathname)s::%(funcName)s:%(lineno)s】 %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S',
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'standard',
        },
        'file': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',     # 轮替文件处理器
            'filename': os.path.join(ROOT_PATH, 'logs', 'test.log'),
            'formatter': 'standard',
            'encoding': 'utf8',
            'maxBytes': 1024*1024,    # 1MB触发轮转
            'backupCount': 5            # 最多保留5个log文件
        },
    },
    'loggers': {
        '': {
            'handlers': ['console', 'file'],
            'level': 'INFO',
            'propagate': True,
        }
    }
}

if __name__ == '__main__':
    print(ROOT_PATH)
